
#ifndef __SDK_TASK__INCLUDE__
#define __SDK_TASK__INCLUDE__

#include "Stream.h"
#include "TaskJourney.h"
#include "KeyValue.h"

namespace nebula { namespace sdk {


//This interface is usage for access the meta-data of a task.
class ITaskMeta
{
public:
	virtual ~ITaskMeta() {};

public:
	//Task ID relevant interface : task-id is managed
	// as a chain, each time the task is fork, a new
	// task-id is generated and attached to the original
	// one. These chain of task can be access by the following
	// 2 functions.

	//GetRootID() will return orginal task id
	// in other word, is the head of the task-id chain
	virtual const char*  GetRootID     ()            = 0;

	//GetID() will return current task id, the current task-id,
	// in other word, is the tail of the task-id chain
	virtual const char*   GetID        ()            = 0;

	//GetParentID return the parent task id of the given one
	virtual const char*   GetParentID  (const char*) = 0;
	virtual const char*   GetParentID  ()            = 0;

	//Return a clone of this one, the task-id of new task is
	// the same with the original
	virtual ITaskMeta*    Clone         ()            = 0;

	//Generate new sub task from this one
	//note: each time a new task is forked, a new task-id is 
	// generated meanwhile
	virtual ITaskMeta*    Fork         ()            = 0;
	virtual ITaskMeta*    Fork         (const char*) = 0;

	//Return the user defined meta-data
	virtual IKey*     GetUserData  ()            = 0;

	//Journey access
	virtual ITaskJourney* GetJourney   ()            = 0;

	//Parse and Compose
	virtual NEBULA_ERROR_CODE Serialize    (IOStream*)   = 0;
	virtual NEBULA_ERROR_CODE UnSerialize  (IIStream*)   = 0;
};

class ITask
{
public:
	virtual ~ITask() {};

	virtual ITaskMeta*        GetTaskMeta()          = 0;
	virtual NEBULA_ERROR_CODE SetTaskMeta(ITaskMeta*)= 0;

	virtual NEBULA_ERROR_CODE Serialize  (IOStream*) = 0;
	virtual NEBULA_ERROR_CODE UnSerialize(IIStream*) = 0;

	virtual NEBULA_ERROR_CODE AnteSerialize  () = 0;
	virtual NEBULA_ERROR_CODE PostUnSerialize() = 0;
};


}}

#endif //end of __SDK_TASK__INCLUDE__

